#include <iostream>
using namespace std;

typedef int ElemType;
typedef struct Node *PtrToNode;
struct Node
{
    ElemType data;
    PtrToNode next;
};
typedef PtrToNode List;

List Read()
{
    cout << "请输入链表元素，以回车结束：" << endl;
    List L = NULL;
    char c;
    while (c = cin.get() != '\n')
    {
        List p = new Node;
        int number;
        cin >> number;
        p->data = number;
        p->next = L;
        L = p;
    }
    return L;
};
void Print(List L)
{
    while (L != NULL)
    {
        cout << L->data << " ";
        L = L->next;
    }
};

List Reverse(List L);

int main()
{
    List L1;
    List L2;

    int n;
    cout << "要输入的元素个数：" << endl;
    cin >> n; // 输入元素个数
    List head = NULL;
    List p = NULL;
    List q = NULL;
    for (int i = 0; i < n; i++) // 分配内存，依次输入元素
    {
        q = new Node;
        cin >> q->data;
        if (L1 == NULL)
        {
            L1 = q;
            p = L1;
        }
        else
        {
            p->next = q;
            p = p->next;
        }
    }
    L2 = Reverse(L1);
    Print(L1);
    Print(L2);
    return 0;
}

List Reverse(List L)
{
    if (L == NULL)
    {
        cout << "输入List为空" << endl;
        return NULL;
    }
    List L1, L2;
    L1 = L2 = NULL;
    while (L != NULL)
    {
        L1 = L->next;
        L->next = L2;
        L2 = L;
        L = L1;
    }
    return L2;
}